package TestDemo;

import java.util.Arrays;
import java.util.Comparator;

/*
abstract class Animal{
    public String name;
    public int age;
    abstract public void eat();
}

class Dog extends Animal{
    @Override
    public void eat() {
        System.out.println(this.name + "qia fan");
    }
}

interface B{
    void hasNum();

}


class Money {
    public double m = 99.99;
}
class Person implements Cloneable{
    public Money money = new Money();
        @Override
    protected Object clone() throws CloneNotSupportedException {
        Money ret = new Money();
        ret.m = this.money.m;
        return ret;
    }
}
*/
class Student implements Comparable<Student>{
    String name;
    int age;
    double score;
    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return o.age - this.age;
    }
}

class StringComparator implements Comparator<Student>{

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
class Money implements Cloneable{
    public double m = 10.5;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "Money{" +
                "m=" + m +
                '}';
    }
}

class Person implements Cloneable{
    public Money money = new Money();
    public int num = 20;
    public String name;
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person tmp = (Person) super.clone();
        tmp.money = (Money) this.money.clone();
        return tmp;
    }

    @Override
    public String toString() {
        return "Person{" +
                "money=" + money +
                ", num=" + num +
                ", name='" + name + '\'' +
                '}';
    }
}

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2 = (Person) person1.clone();
        person1.name = "haha";
        person2.name = "wuhu";
        person2.money.m = 20.0;
        System.out.println(person1);
        System.out.println(person2);
    }
    public static void main2(String[] args) {
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",10,45.5);
        students[1] = new Student("anbo",15,25.5);
        students[2] = new Student("wangwu",20,35.5);
        Arrays.sort(students,new StringComparator());
        System.out.println(Arrays.toString(students));
    }
    /*public static void eat(Animal animal){
        animal.eat();
    }
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.name = "jack";
        eat(dog);
    }*/
    /*public static void main2(String[] args) throws CloneNotSupportedException {
        Person person1 = new Person();
        Person person2 = (Person)person1.clone();
        System.out.println("通过person2修改前的结果");
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
        person2.money.m = 13.6;
        System.out.println("通过person2修改后的结果");
        System.out.println(person1.money.m);
        System.out.println(person2.money.m);
    }*/
}